//
//  SAStatisticsBusinessHeaderView.m
//  saasRetail
//
//  Created by mac on 2022/7/11.
//

#import "SAStatisticsBusinessHeaderView.h"
#import "SAStatisticsBusinessModel.h"

@interface SAStatisticsBusinessHeaderView ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *numLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UIImageView *imageV;

@property (nonatomic, strong) UILabel *numLab2;
@property (nonatomic, strong) UILabel *priceLab2;
@property (nonatomic, strong) UIButton *showMoneyBtn;

@end

@implementation SAStatisticsBusinessHeaderView
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAStatisticsBusinessModel *)model {
    _model = model;
    self.titleLab.text = model.titleName;
    self.numLab.text = model.count;
    self.priceLab.text = model.price;
    self.imageV.image = [UIImage imageNamed:model.icon];
    self.showMoneyBtn.hidden = YES;
    
    if ([model.titleName isEqualToString:@"调配入库"] || [model.titleName isEqualToString:@"调配出库"]) {
        self.numLab2.hidden = NO;
        self.priceLab2.hidden = NO;
        self.numLab.frame = SARectMake(100, 10, 110, 20);
        self.priceLab.frame = CGRectMake(kScreenWidth - kScaleNum(160), kScaleNum(10), kScaleNum(130), kScaleNum(20));
        self.numLab.text = model.enterCount;
        self.priceLab.text = model.enterPrice;
        self.numLab2.text = model.outCount;
        self.priceLab2.text = model.outPrice;
    }else {
        self.showMoneyBtn.hidden = NO;
        self.showMoneyBtn.selected = model.isSelect;
        self.numLab.frame = SARectMake(100, 0, 110, 64);
        self.priceLab.frame = CGRectMake(kScreenWidth - kScaleNum(160), 0, kScaleNum(130), kScaleNum(64));
        self.numLab2.hidden = YES;
        self.priceLab2.hidden = YES;
    }
}

-(void)clickedBhowMoneyBtn {
    !self.selectBlock ?: self.selectBlock();
}

-(void)initUI {
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.imageV];
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.numLab];
    [self.contentView addSubview:self.priceLab];
    [self.contentView addSubview:self.numLab2];
    [self.contentView addSubview:self.priceLab2];
    
    UIButton *showMoneyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [showMoneyBtn setImage:[UIImage imageNamed:@"SA_arrow_down"] forState:UIControlStateNormal];
    [showMoneyBtn setImage:[UIImage imageNamed:@"SA_arrow_up"] forState:UIControlStateSelected];
    showMoneyBtn.frame = CGRectMake(0, 0, kScreenWidth, kScaleNum(64));
    showMoneyBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    showMoneyBtn.imageEdgeInsets = kEdgeInsetsMake(0, 0, 0, 15);
    [showMoneyBtn addTarget:self action:@selector(clickedBhowMoneyBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:showMoneyBtn];
    self.showMoneyBtn = showMoneyBtn;
}

-(UIImageView *)imageV {
    if (!_imageV) {
        _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(kScaleNum(30), kScaleNum(8), kScaleNum(27), kScaleNum(27))];
    }
    return _imageV;
}

-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:SARectMake(10, 42, 67, 17)];
        _titleLab.textColor = kBlackColor;
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.font = kFont(15);
    }
    return _titleLab;
}

-(UILabel *)numLab {
    if (!_numLab) {
        _numLab = [[UILabel alloc] initWithFrame:SARectMake(100, 0, 110, 64)];
        _numLab.textColor = kBlackColor;
        _numLab.font = kFont(15);
        _numLab.textAlignment = NSTextAlignmentLeft;
    }
    return _numLab;
}

-(UILabel *)priceLab {
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - kScaleNum(160), 0, kScaleNum(130), kScaleNum(64))];
        _priceLab.textColor = kBlackColor;
        _priceLab.font = kFont(15);
        _priceLab.textAlignment = NSTextAlignmentLeft;
    }
    return _priceLab;
}

-(UILabel *)numLab2 {
    if (!_numLab2) {
        _numLab2 = [[UILabel alloc] initWithFrame:SARectMake(100, 34, 110, 20)];
        _numLab2.textColor = kBlackColor;
        _numLab2.font = kFont(15);
        _numLab2.textAlignment = NSTextAlignmentLeft;
    }
    return _numLab2;
}

-(UILabel *)priceLab2 {
    if (!_priceLab2) {
        _priceLab2 = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - kScaleNum(160), kScaleNum(34), kScaleNum(130), kScaleNum(20))];
        _priceLab2.textColor = kBlackColor;
        _priceLab2.font = kFont(15);
        _priceLab2.textAlignment = NSTextAlignmentLeft;
    }
    return _priceLab2;
}

@end
